import Replacer, FileCreation
import UUID

def generate_proj(src_dir, project_path_name, project_type, template_postfix):

	# extract the project path and name from input
	tokens = project_path_name.split( '/' )

	#src_dir = "../src"
	project_name = ""

	for i in range(len(tokens)):
			src_dir = src_dir + '/' + tokens[i]
			project_name = tokens[i]

	# ask fot project type
	is_test = False

	if( project_type == "Tests" ):
			in_file = open("project_test" + template_postfix + ".template")
			project_name = project_name + "_tests"
			src_dir = src_dir + "/tests"
			is_test = True

	else:
			if( project_type == "Lib" ):
					in_file = open("project_lib" + template_postfix + ".template")

			else:
					in_file = open("project_exe" + template_postfix + ".template")

			#end if

	#end if

	# create project path & vcproj file
	FileCreation.create_path(src_dir)

	if( is_test == True ):
			out_file = open( src_dir + "/main.cpp", "w")
			out_file.write('#include "UnitTest++.h"\n\nint main(int, char const *[])\n{\n\treturn UnitTest::RunAllTests();\n}')
			out_file.close()

	out_file = open( src_dir + "/" + project_name + ".vcproj", "w")

	mapping_dict = { r"{GUID}" : lambda : "{" + UUID.uuid() + "}",
									 r"{PROJECT_NAME}" : lambda : project_name }

	Replacer.replace(in_file, mapping_dict, out_file)

	in_file.close()
	out_file.close()

#end def